package com.company.基础.Array.twoDimensional.exer;

import java.util.Random;

/**
 * 题目：创建一个长度为6的int型数组，要求数组元素的值在1-30之间，且是随机赋值，同时，要求元素值各不相同
 */
public class Array3 {
    public static void main(String[] args) {
        int [] arr=new int[6];
        Random random=new Random();
        for (int i = 0; i <arr.length ; i++) {
            int num = random.nextInt(31);
            if (getNum(num,random,arr)) {
                arr[i]=num;
            }
            System.out.println(arr[i]);
        }
    }
    public static boolean getNum( int num,Random random,int[] arr){

        boolean flag=true;
        for (int i = 0; i <arr.length ; i++) {
            if (num==arr[i]){
                flag=false;
                num = random.nextInt(31);
                getNum(num,random,arr);
            }
        }
        return flag;
    }
}
